package cn.zhizihua.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 订单
 */
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) //关联查询结果展示包含非空的字段  （如果字段是空的，转JSON时自动忽略掉了）
public class Order {
    private Integer orderId; //主键 数字  自增
    private String orderNumber; //字符串编号 通常有生成策略
    private Integer userId; //用户编号   哪个用户在下单
    private Integer businessId; //商家编号   在哪个商家下单

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")  //将时间戳转化为指定格式
    private Date orderDate;
    private Double orderTotal;
    private Integer addressId; //用户地址编号
    private Integer orderState; //状态  0 未支付  1 已支付

    //关联的表
    private User user;
    private Business business;
    private Address address;

    //不关联外键的构造函数
    public Order(Integer orderId, String orderNumber, Integer userId, Integer businessId, Date orderDate, Double orderTotal, Integer addressId, Integer orderState) {
        this.orderId = orderId;
        this.orderNumber = orderNumber;
        this.userId = userId;
        this.businessId = businessId;
        this.orderDate = orderDate;
        this.orderTotal = orderTotal;
        this.addressId = addressId;
        this.orderState = orderState;
    }

    //存放订单详情
//    private List<OrderDetail> orderDetailList;
    private List<OrderDetail> orderDetailList = new ArrayList<>();
}
